Page({
  data: {
    tltArr:[
      {title:'淘宝会员名称',id:'userNick'},
      {title:'奖品名称',id:'prizeName'},
      {title:'留资信息',id:'info'},
      {title:'发奖类型',id:'type'},
      {title:'奖品类型',id:'prizeType'},
      {title:'获奖时间',id:'createTime'},
      {title:'发货状态',id:'status'}
		],
		selectList:[],
		drawData:[],
		pageIdx:1,
		pageNum:1000,
		total:0,

		//****条件*********
		nickName:'',
		endTime:'',
		startTime:'',
		prizeName:'',
		num:1,

    activityId:'',
    seefahuo:false,
    btnStatus:0,   //0  为提交  1为关闭
    exportLink:"",    //导出链接
    exportLinkTc:false,
    
  },
  
  //查看发货
  seefh(e){

    //console.log(e);

    this.setData({
      idd:e.currentTarget.dataset.id
    })

    this.data.drawData.filter((i)=>{
      if(i.id == e.currentTarget.dataset.id){

        //console.log(i.prizeType);

        if( i.prizeType == "实物奖" ){

          if(i.status == "1"){ 
            //my.alert({content:"发货"})

            console.log("发货详情",i)
            this.setData({
              
              kdgs:i.expressCompany,
              ddh:i.expressNo,
              fahuotime:i.expressTime,
              btnStatus:1,
              seefahuo:true

            })

          }else if(i.status == "0"){
            
            this.setData({
              seefahuo:true,
              btnStatus:0
            })

          }

        }else{
          my.showToast({content:"该奖品自动发放！"})
        }

        
      }
    })

  },
  
  // 保存发货信息
  onSubmin(){

    let o={
      "expressCompany": this.data.gs,
      "expressNo": this.data.dh,
      "id": this.data.idd
    }

    console.info(o)

    getApp().cloud.application.httpRequest({
      'path' : '/api/b/saveExpression', 
      'method':'POST',
			'headers':{ "Content-Type":"application/json"},
      'body':o,
    }).then(res => {
			console.info('保存发货信息===》',res)

      if(res.code == 200){
        this.setData({
          seefahuo:false
        })

        this.search();

        my.showToast({content:"保存成功"});


      }else{
        my.showToast({content:res.msg});
      }

      console.info('=================================>>>>>>>>>>>>>',res.data)
      
		})
  },

  //关闭弹窗
  closeSeefahuo(){
    this.setData({
      kdgs:"",
      ddh:"",
      fahuotime:"",
      seefahuo:false
    })
  },

  //导出
  export(){

    if(this.data.activityId){
      let o = {
        "activityId":this.data.activityId
      }
      
      getApp().cloud.application.httpRequest({
        'path' : '/api/b/exportPrizeList', 
        'method':'POST',
        'headers':{ "Content-Type":"application/json"},
        'body':o,
      }).then(res => {

        console.info('导出=======》',res)

        if(res.code != 200)return;

        //输出一个链接
        this.setData({
          exportLink:res.data,
          exportLinkTc:true
        })

        this.search()
        
      })

    }else{
      
      my.showToast({content:"请选择一个活动进行导出！"});
      

    }
  
  },

  //复制导出表格链接
  linkCopy(){

    my.setClipboard({
      text: this.data.exportLink,
      success: res => {
        my.showToast({content:"复制成功"});
      },
      fail: res => {
      }
    });

  },

  //关闭
  closeExport(){
    this.setData({
      exportLinkTc:false
    })
  },

	//获取权益列表
	RIlist(o){
		getApp().cloud.application.httpRequest({
      'path' : '/api/b/prizeList', 
      'method':'POST',
			'headers':{ "Content-Type":"application/json"},
      'body':o,
    }).then(res => {
			console.info('权益领取列表===》',res)

			if(res.code != 200)return;

			let lin = JSON.parse(JSON.stringify(res.data.list))

			lin.map((v,i) => {
				v.type = v.type == 1 ? '排行榜奖品' : 'pk奖品';
        v.prizeType = v.prizeType == 1 ? '实物奖' : '虚拟奖';
        v.info =  v.info ? v.info : '-'
			})

			this.setData({
        drawData:lin,
				total:res.data.total
			})

      console.info('=================================>>>>>>>>>>>>>',res.data)
      
		})
	},

	//分页器
	pageChange(e){
		let num = e.detail.value;

		this.setData({
			num:num
		})

		let body = {
									"endTime": this.data.endTime,
									"nickName": this.data.nickName,
									"pageNo": num,
									"pageSize": this.data.pageNum,
									"prizeName": this.data.prizeName,
									"startTime": this.data.startTime
								}

		this.RIlist(body)
		
	},

	//日期输入
	dateChange(e){

		this.setData({
			startTime:e.detail.value[0],
			endTime:e.detail.value[1]
		})

	},

	//文本框属入
	inpChange(e){
		let name = e.target.dataset.name;

		this.setData({
			[name]:e.detail.value
		})
		
  },
  
  //下拉框
  selChange(e){
    this.setData({
			activityId:e.detail.value
		})
  },

	//重置按钮
	reset(){
		this.setData({
			nickName:'',
			endTime:'',
			startTime:'',
			prizeName:'',
			num:1
		})

		let body = {
			"endTime": '',
			"nickName": '',
			"pageNo": 1,
			"pageSize": this.data.pageNum,
			"prizeName": '',
			"startTime": ''
		}

		this.RIlist(body)
	},

	search(){
		let body = {
					"endTime": this.data.endTime,
					"nickName": this.data.nickName,
					"pageNo": this.data.num,
					"pageSize": this.data.pageNum,
					"startTime": this.data.startTime,
					"activityId":this.data.activityId
				}

		this.RIlist(body)
	},


	requ(){

		getApp().cloud.application.httpRequest({
      'path' : '/api/b/getAppName', 
      'method':'GET',
			'headers':{ "Content-Type":"application/json"},
      'body':{
			},
    }).then(res => {
			console.info('活动列表=====》',res.data)
			
			this.setData({
				selectList:res.data
			})
			
		})

	},

	onShow(){

		//this.search()
		this.requ()
		
	},

  onLoad() {
    //this.search()
  },
});
